<?php
class baseController
{
	private 	$template ;
	protected 	$vars = array() ;	// variables para el template
	private 	$controller ; 		// para la ruta del template
	private 	$action ;			// para la ruta del template
	protected	$model ;			// model
	
	public function __construct( $controllerName, $actionName )
	{
		$this->template 	= new template( substr( $controllerName, 0, -10 ), $actionName );
		$this->set( 'title', _appname ) ;
		$this->controller 	= substr( $controllerName, 0, -10 ) ;
		$this->action		= $actionName ;
		$this->model		= $this->controller . 'Model' ;
		$this->model		= new  $this->model ;
	}
	
	public function index()
	{
	
	}
	
	/* 
	 * setear variables del template
	 *
	 * @param $name string
	 *	nombre de la variable
	 *
	 * @param $value string
	 *	valor de la variable
	 *
	 */
	public function set( $name, $value )
	{
		$this->template->set( $name, $value ) ;
	}
	
	/* obtener $_GET */
	public function get( $var )
	{
			if( isset( $_GET[ $var ] ) )
			{
				return( $_GET[ $var ] ) ;
			}
			return( false ) ;
	}
	
	/* obtener $_POST */
	public function post( $var )
	{
		if( isset( $_POST[ $var ] ) )
		{
			return( $_POST[ $var ] ) ;
		}
		return( false ) ;
	}
	
	/* obtener $_COOKIE */
	public function cookie( $var )
	{
		if( isset( $_COOKIE[ $var ] ) )
		{
			return( $_COOKIE[ $var ] ) ;
		}
		return( false ) ;
	}
	
	/* mostrar la vista (template) */
	public function render()
	{
		// seteo las variables en la vista
		foreach( $this->vars as $name => $value )
		{
			$this->set( $name, $value ) ;
		}
		
		// muestro
		$this->template->render( $this->controller, $this->action ) ;
	}
	
	
} // class end